#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cassert>
#include <cstring>
#include <algorithm>
#define fi first
#define se second
#define ep emplace
#define MISAKA main
#define mid (L+R>>1)
#define ll long long
#define mkp make_pair
#define eb emplace_back
#define pii pair<ll,ll>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define _rep(i,a,b) for(int i=a;i>=b;--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define FIO(FILE) freopen(FILE".in","r",stdin),freopen(FILE".out","w",stdout)
using namespace std;
bool __st;
inline ll read(){
    char ch=getchar();ll f=1,x=0;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
const int N=4e5+10,mod=998244353;
ll n,cnt,a[N],b[N];int rt,mp[N];
struct node{int ls,rs,s;ll k,S1,S2;}t[N*20];
void upd(int &x,int p,int k,int L=1,int R=n){
    if(!x) x=++cnt;
    t[x].s+=k,t[x].k+=b[p]*k;
    if(L==R){t[x].S1+=b[p]*k,t[x].S2+=b[p]*k;return;}
    if(p<=mid) upd(t[x].ls,p,k,L,mid);
    else upd(t[x].rs,p,k,mid+1,R);
    t[x].S1=t[t[x].ls].S1+t[t[x].ls].k*t[t[x].rs].s+t[t[x].rs].S1;
    t[x].S2=t[t[x].ls].S2+t[t[x].rs].S2+t[t[x].rs].k*t[t[x].ls].s;
}
ll find(int x,ll k,int L=1,int R=n){
    if(!x) return 0;if(L==R) return t[x].k<=k;
    if(t[t[x].ls].k>=k) return find(t[x].ls,k,L,mid);
    return find(t[x].rs,k-t[t[x].ls].k,mid+1,R)+t[t[x].ls].s;
}
ll sum(int x,int k,int L=1,int R=n){
    if(!k) return 0;if(L==R) return t[x].k;
    if(t[t[x].ls].s>=k) return sum(t[x].ls,k,L,mid);
    return sum(t[x].rs,k-t[t[x].ls].s,mid+1,R)+t[t[x].ls].k;
}
struct T{ll a,b,c;};
T mg1(T a,T b){return T{a.a+a.b*b.c+b.a,a.b+b.b,a.c+b.c};}
T qry1(int x,int p,int L=1,int R=n){
    if(p<=0) return T{0,0,0};
    if(p==t[x].s) return T{t[x].S1,t[x].k,t[x].s};
    if(t[t[x].ls].s>=p) return qry1(t[x].ls,p,L,mid);
    int ls=t[x].ls;
    return mg1(T{t[ls].S1,t[ls].k,t[ls].s},qry1(t[x].rs,p-t[ls].s,mid+1,R));
}
T mg2(T a,T b){return T{a.a+b.a+b.b*a.c,a.b+b.b,a.c+b.c};}
T qry2(int x,int p,int L=1,int R=n){
    if(p<=0) return T{0,0,0};
    if(p==t[x].s) return T{t[x].S2,t[x].k,t[x].s};
    if(t[t[x].rs].s>=p) return qry2(t[x].rs,p,mid+1,R);
    int rs=t[x].rs;
    return mg2(qry2(t[x].ls,p-t[rs].s,L,mid),T{t[rs].S2,t[rs].k,t[rs].s});
}
void misaka(){
    n=read();
    rep(i,1,n) a[i]=b[i]=read();
    sort(b+1,b+n+1);int len=unique(b+1,b+n+1)-b;
    rep(i,1,n) a[i]=lower_bound(b+1,b+len,a[i])-b;
    rep(_,1,n){ll x=a[_];
        upd(rt,x,mp[x]?-1:1),mp[x]^=1;
        ll s=t[rt].s;
        if(s<=1){puts("0");continue;}
        int l=2,r=s;
        while(r>=l){
            int m=l+r>>1;
            if(sum(rt,m)<t[rt].k-sum(rt,s-m+1)) l=m+1;
            else r=m-1;
        }
        printf("%lld\n",t[rt].S2-qry2(rt,r-1).a-t[rt].S1+qry1(rt,r).a-sum(rt,1));
    }
}
bool __ed;
signed MISAKA(){
    #ifdef LOCAL_MSK
    atexit([](){
    debug("\n%.3lfs  ",(double)clock()/CLOCKS_PER_SEC);
    debug("%.3lfMB\n",abs(&__st-&__ed)/1024./1024);});
    #endif
    FIO("kte");
    // freopen("kte3.in","r",stdin);freopen("kte3.ans","w",stdout);
    // system("fc kte3.out kte3.ans");
    // freopen("data.in","r",stdin);
    int T=1;
    while(T--) misaka();
    return 0;
}
